/*****************************************************************************
	File Name:			HPlayer.cpp
	Authors:			Marc Willis, Trey Turley, Thomas Lee
	Description:		Defines the functions for HPlayer in the game Tron.
	Date Modified:		08/07/2010
						-Modifed to adjust to changes in Player class
						08/01/2010
						-File Created
*****************************************************************************/

#include "HPlayer.h"

/*****************************************************************************
	Function Name:		HPlayer()
	Description:		Default constructor for the HPlayer class, creates a
						HPlayer with default stats
	Input:
		(none)
	Output:
		(none)
*****************************************************************************/
HPlayer::HPlayer():Player()
{
	ctrlScheme=CTRL_ARROWS;
}
/*****************************************************************************
	Function Name:		HPlayer(int,int,int,int)
	Description:		Constructor for the HPlayer class, creates a HPlayer
						with the given stats
	Input:
		int x			x of the player
		int y			y of the player
		int dir			direction of the player
		int color		color of the player
		GameMap &g		GameMap to be referenced
	Output:
		(none)
*****************************************************************************/
HPlayer::HPlayer(int x,int y,int dir,int color, GameMap &g):Player(x,y,dir,color,g)
{
	ctrlScheme=CTRL_ARROWS;
}
/*****************************************************************************
	Function Name:		HPlayer(int,int,int,int,int)
	Description:		Constructor for the HPlayer class, creates a HPlayer
						with the given stats and control scheme
	Input:
		int x			x of the player
		int y			y of the player
		int dir			direction of the player
		int color		color of the player
		GameMap &g		GameMap to be referenced
		int ctrlScheme	control scheme of the player
	Output:
		(none)
*****************************************************************************/
HPlayer::HPlayer(int x,int y,int dir,int color,GameMap &g, int ctrlScheme)
		:Player(x,y,dir,color,g)
{
	this->ctrlScheme=ctrlScheme;
}
/*****************************************************************************
	Function Name:		getNextDir(GameMap)
	Description:		Gets the next direction based on the key pressed
	Input:
		GameMap g		the GameMap the player is on.
	Output:
		int				the direction
*****************************************************************************/
void HPlayer::refreshDir()
{
	if(ctrlScheme==CTRL_ARROWS)
	{
		//Down is pressed (and not up)
		if(KEYDOWN(VK_DOWN)&&!KEYDOWN(VK_UP)&&dir!=DIR_UP)
		{
			dir= DIR_DOWN;
		}
		//Up is pressed (and not down)
		if(!KEYDOWN(VK_DOWN)&&KEYDOWN(VK_UP)&&dir!=DIR_DOWN)
		{
			dir= DIR_UP;
		}
		//Left is pressed (and not right)
		if(KEYDOWN(VK_LEFT)&&!KEYDOWN(VK_RIGHT)&&dir!=DIR_RIGHT)
		{
			dir= DIR_LEFT;
		}
		//Right is pressed (and not left)
		if(!KEYDOWN(VK_LEFT)&&KEYDOWN(VK_RIGHT)&&dir!=DIR_LEFT)
		{
			dir= DIR_RIGHT;
		}
	}
	if(ctrlScheme==CTRL_WASD)
	{
		//Down is pressed (and not up)
		if(KEYDOWN(VK_KEY_S)&&!KEYDOWN(VK_KEY_W)&&dir!=DIR_UP)
		{
			dir= DIR_DOWN;
		}
		//Up is pressed (and not down)
		if(!KEYDOWN(VK_KEY_S)&&KEYDOWN(VK_KEY_W)&&dir!=DIR_DOWN)
		{
			dir= DIR_UP;
		}
		//Left is pressed (and not right)
		if(KEYDOWN(VK_KEY_A)&&!KEYDOWN(VK_KEY_D)&&dir!=DIR_RIGHT)
		{
			dir= DIR_LEFT;
		}
		//Right is pressed (and not left)
		if(!KEYDOWN(VK_KEY_A)&&KEYDOWN(VK_KEY_D)&&dir!=DIR_LEFT)
		{
			dir= DIR_RIGHT;
		}
	}
	if(ctrlScheme==CTRL_IJKL)
	{
		//Down is pressed (and not up)
		if(KEYDOWN(VK_KEY_K)&&!KEYDOWN(VK_KEY_I)&&dir!=DIR_UP)
		{
			dir= DIR_DOWN;
		}
		//Up is pressed (and not down)
		if(!KEYDOWN(VK_KEY_K)&&KEYDOWN(VK_KEY_I)&&dir!=DIR_DOWN)
		{
			dir= DIR_UP;
		}
		//Left is pressed (and not right)
		if(KEYDOWN(VK_KEY_J)&&!KEYDOWN(VK_KEY_L)&&dir!=DIR_RIGHT)
		{
			dir= DIR_LEFT;
		}
		//Right is pressed (and not left)
		if(!KEYDOWN(VK_KEY_J)&&KEYDOWN(VK_KEY_L)&&dir!=DIR_LEFT)
		{
			dir= DIR_RIGHT;
		}
	}
	if(ctrlScheme==CTRL_NUM)
	{
		//Down is pressed (and not up)
		if(KEYDOWN(VK_NUMPAD5)&&!KEYDOWN(VK_NUMPAD8)&&dir!=DIR_UP)
		{
			dir= DIR_DOWN;
		}
		//Up is pressed (and not down)
		if(!KEYDOWN(VK_NUMPAD5)&&KEYDOWN(VK_NUMPAD8)&&dir!=DIR_DOWN)
		{
			dir= DIR_UP;
		}
		//Left is pressed (and not right)
		if(KEYDOWN(VK_NUMPAD4)&&!KEYDOWN(VK_NUMPAD6)&&dir!=DIR_RIGHT)
		{
			dir= DIR_LEFT;
		}
		//Right is pressed (and not left)
		if(!KEYDOWN(VK_NUMPAD4)&&KEYDOWN(VK_NUMPAD6)&&dir!=DIR_LEFT)
		{
			dir= DIR_RIGHT;
		}
	}
}
